



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class sysdiagramsDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public sysdiagramsDB()
        {
        }

        public sysdiagramsDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<sysdiagrams> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<sysdiagrams> lstRet = new List<sysdiagrams>();

            string strQuery = " select " + strTop  + " * from dbo.[sysdiagrams]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    sysdiagrams obj = new sysdiagrams();
 if (dr["name"] != DBNull.Value)
                    {
                        obj.name = (System.String)dr["name"];
                    }
                    else
                    {
                        obj.name = "";
                    } 
 if (dr["principal_id"] != DBNull.Value)
                    {
                        obj.principal_id = (System.Int32)dr["principal_id"];
                    }
                    else
                    {
                        obj.principal_id = -1;
                    } 
 if (dr["diagram_id"] != DBNull.Value)
                    {
                        obj.diagram_id = (System.Int32)dr["diagram_id"];
                    }
                    else
                    {
                        obj.diagram_id = -1;
                    } 
 if (dr["version"] != DBNull.Value)
                    {
                        obj.version = (System.Int32?)dr["version"];
                    }
                    else
                    {
                        obj.version = null;
                    } 
 if (dr["definition"] != DBNull.Value)
                    {
                        obj.definition = (byte[])dr["definition"];
                    }
                    else
                    {
                        obj.definition = null;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<sysdiagrams> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<sysdiagrams> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , sysdiagrams obj)
        {
            
            

                    DbParameter prmname = con.createParameter();
                    prmname.ParameterName = "@name";
                    prmname.DbType =DbType.String;
                    if (obj.name == null)
                    {
                        prmname.Value = DBNull.Value;
                    }
                    else
                    {
                        prmname.Value = obj.name;
                    }
                

                    


                    DbParameter prmprincipal_id = con.createParameter();
                    prmprincipal_id.ParameterName = "@principal_id";
                    prmprincipal_id.DbType =DbType.Int32;
                    if (obj.principal_id == null)
                    {
                        prmprincipal_id.Value = DBNull.Value;
                    }
                    else
                    {
                        prmprincipal_id.Value = obj.principal_id;
                    }
                

                    


                    DbParameter prmversion = con.createParameter();
                    prmversion.ParameterName = "@version";
                    prmversion.DbType =DbType.Int32;
                    if (obj.version == null)
                    {
                        prmversion.Value = DBNull.Value;
                    }
                    else
                    {
                        prmversion.Value = obj.version;
                    }
                

                    


                    DbParameter prmdefinition = con.createParameter();
                    prmdefinition.ParameterName = "@definition";
                    prmdefinition.DbType =DbType.Binary;
                    if (obj.definition == null)
                    {
                        prmdefinition.Value = DBNull.Value;
                    }
                    else
                    {
                        prmdefinition.Value = obj.definition;
                    }
                

                    


           



            string strQuery = " insert into dbo.[sysdiagrams] ([name],[principal_id],[version],[definition]) VALUES (@name,@principal_id,@version,@definition) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmname,prmprincipal_id,prmversion,prmdefinition);


                    try
                    {
                        obj.diagram_id = System.Int32.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.diagram_id = -1;
                    }


                    


           

        }



        public void Insert(sysdiagrams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, sysdiagrams obj)
        {
            
            

                    DbParameter prmname = con.createParameter();
                    prmname.ParameterName = "@name";
                    prmname.DbType =DbType.String;
                    if (obj.name == null)
                    {
                        prmname.Value = DBNull.Value;
                    }
                    else
                    {
                        prmname.Value = obj.name;
                    }
                

                    


                    DbParameter prmprincipal_id = con.createParameter();
                    prmprincipal_id.ParameterName = "@principal_id";
                    prmprincipal_id.DbType =DbType.Int32;
                    if (obj.principal_id == null)
                    {
                        prmprincipal_id.Value = DBNull.Value;
                    }
                    else
                    {
                        prmprincipal_id.Value = obj.principal_id;
                    }
                

                    


                    DbParameter prmdiagram_id = con.createParameter();
                    prmdiagram_id.ParameterName = "@diagram_id";
                    prmdiagram_id.DbType =DbType.Int32;
                    if (obj.diagram_id == null)
                    {
                        prmdiagram_id.Value = DBNull.Value;
                    }
                    else
                    {
                        prmdiagram_id.Value = obj.diagram_id;
                    }
                

                    


                    DbParameter prmversion = con.createParameter();
                    prmversion.ParameterName = "@version";
                    prmversion.DbType =DbType.Int32;
                    if (obj.version == null)
                    {
                        prmversion.Value = DBNull.Value;
                    }
                    else
                    {
                        prmversion.Value = obj.version;
                    }
                

                    


                    DbParameter prmdefinition = con.createParameter();
                    prmdefinition.ParameterName = "@definition";
                    prmdefinition.DbType =DbType.Binary;
                    if (obj.definition == null)
                    {
                        prmdefinition.Value = DBNull.Value;
                    }
                    else
                    {
                        prmdefinition.Value = obj.definition;
                    }
                

                    


           



            string strQuery = " update dbo.[sysdiagrams] set [name]=@name,[principal_id]=@principal_id,[version]=@version,[definition]=@definition where  [diagram_id]=@diagram_id  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmname,prmprincipal_id,prmdiagram_id,prmversion,prmdefinition);

            

        }


        public void Update(sysdiagrams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, sysdiagrams obj)
        {

            

                    DbParameter prmdiagram_id = con.createParameter();
                    prmdiagram_id.ParameterName = "@diagram_id";
                    prmdiagram_id.DbType =DbType.Int32;
                    if (obj.diagram_id == null)
                    {
                        prmdiagram_id.Value = DBNull.Value;
                    }
                    else
                    {
                        prmdiagram_id.Value = obj.diagram_id;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[sysdiagrams]  where  [diagram_id]=@diagram_id  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmdiagram_id );  

             



        }


        public void Delete( sysdiagrams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<sysdiagrams> getsysdiagramsByname(ClassDataHandler con,System.String name)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();


                        DbParameter prmname = con.createParameter();
                        prmname.ParameterName = "@name";
                        prmname.DbType = DbType.String;
                        if (name == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmname.Value = name;
                        }


                        lstRet = Select(con, "" , " where [name]=@name ", prmname);



                        return lstRet;

                    }


                    public List<sysdiagrams> getsysdiagramsByname(System.String name)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getsysdiagramsByname(con, name);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<sysdiagrams> getsysdiagramsByprincipal_id(ClassDataHandler con,System.Int32 principal_id)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();


                        DbParameter prmprincipal_id = con.createParameter();
                        prmprincipal_id.ParameterName = "@principal_id";
                        prmprincipal_id.DbType = DbType.Int32;
                        if (principal_id == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmprincipal_id.Value = principal_id;
                        }


                        lstRet = Select(con, "" , " where [principal_id]=@principal_id ", prmprincipal_id);



                        return lstRet;

                    }


                    public List<sysdiagrams> getsysdiagramsByprincipal_id(System.Int32 principal_id)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getsysdiagramsByprincipal_id(con, principal_id);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<sysdiagrams> getsysdiagramsBydiagram_id(ClassDataHandler con,System.Int32 diagram_id)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();


                        DbParameter prmdiagram_id = con.createParameter();
                        prmdiagram_id.ParameterName = "@diagram_id";
                        prmdiagram_id.DbType = DbType.Int32;
                        if (diagram_id == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmdiagram_id.Value = diagram_id;
                        }


                        lstRet = Select(con, "" , " where [diagram_id]=@diagram_id ", prmdiagram_id);



                        return lstRet;

                    }


                    public List<sysdiagrams> getsysdiagramsBydiagram_id(System.Int32 diagram_id)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getsysdiagramsBydiagram_id(con, diagram_id);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<sysdiagrams> getsysdiagramsByversion(ClassDataHandler con,System.Int32? version)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();


                        DbParameter prmversion = con.createParameter();
                        prmversion.ParameterName = "@version";
                        prmversion.DbType = DbType.Int32;
                        if (version == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmversion.Value = version;
                        }


                        lstRet = Select(con, "" , " where [version]=@version ", prmversion);



                        return lstRet;

                    }


                    public List<sysdiagrams> getsysdiagramsByversion(System.Int32? version)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getsysdiagramsByversion(con, version);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<sysdiagrams> getsysdiagramsBydefinition(ClassDataHandler con,byte[] definition)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();


                        DbParameter prmdefinition = con.createParameter();
                        prmdefinition.ParameterName = "@definition";
                        prmdefinition.DbType = DbType.Binary;
                        if (definition == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmdefinition.Value = definition;
                        }


                        lstRet = Select(con, "" , " where [definition]=@definition ", prmdefinition);



                        return lstRet;

                    }


                    public List<sysdiagrams> getsysdiagramsBydefinition(byte[] definition)
                    {
                        List<sysdiagrams> lstRet = new List<sysdiagrams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getsysdiagramsBydefinition(con, definition);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<sysdiagrams> Search(ClassDataHandler con, sysdiagrams obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.name != "")
                    {
                        DbParameter prmname = con.createParameter();
                        prmname.ParameterName = "@name";
                        prmname.DbType =DbType.String;
                        if (obj.name == null)
                        {
                            prmname.Value = DBNull.Value;
                        }
                        else
                        {
                            prmname.Value = obj.name;
                        }
                        strWhere += " [name]=@name AND ";
                        lstParameters.Add(prmname);
                     }



                    

                    if (obj.principal_id != -1)
                    {
                        DbParameter prmprincipal_id = con.createParameter();
                        prmprincipal_id.ParameterName = "@principal_id";
                        prmprincipal_id.DbType =DbType.Int32;
                        if (obj.principal_id == null)
                        {
                            prmprincipal_id.Value = DBNull.Value;
                        }
                        else
                        {
                            prmprincipal_id.Value = obj.principal_id;
                        }
                        strWhere += " [principal_id]=@principal_id AND ";
                        lstParameters.Add(prmprincipal_id);
                     }



                    

                    if (obj.diagram_id != -1)
                    {
                        DbParameter prmdiagram_id = con.createParameter();
                        prmdiagram_id.ParameterName = "@diagram_id";
                        prmdiagram_id.DbType =DbType.Int32;
                        if (obj.diagram_id == null)
                        {
                            prmdiagram_id.Value = DBNull.Value;
                        }
                        else
                        {
                            prmdiagram_id.Value = obj.diagram_id;
                        }
                        strWhere += " [diagram_id]=@diagram_id AND ";
                        lstParameters.Add(prmdiagram_id);
                     }



                    

                    if (obj.version != null)
                    {
                        DbParameter prmversion = con.createParameter();
                        prmversion.ParameterName = "@version";
                        prmversion.DbType =DbType.Int32;
                        if (obj.version == null)
                        {
                            prmversion.Value = DBNull.Value;
                        }
                        else
                        {
                            prmversion.Value = obj.version;
                        }
                        strWhere += " [version]=@version AND ";
                        lstParameters.Add(prmversion);
                     }



                    

                    if (obj.definition != null)
                    {
                        DbParameter prmdefinition = con.createParameter();
                        prmdefinition.ParameterName = "@definition";
                        prmdefinition.DbType =DbType.Binary;
                        if (obj.definition == null)
                        {
                            prmdefinition.Value = DBNull.Value;
                        }
                        else
                        {
                            prmdefinition.Value = obj.definition;
                        }
                        strWhere += " [definition]=@definition AND ";
                        lstParameters.Add(prmdefinition);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<sysdiagrams> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<sysdiagrams> Search(sysdiagrams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<sysdiagrams> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<sysdiagrams> SearchOrLike(ClassDataHandler con, sysdiagrams obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.name != "")
                    {
                        DbParameter prmname = con.createParameter();
                        prmname.ParameterName = "@name";
                        prmname.DbType =DbType.String;
                        if (obj.name == null)
                        {
                            prmname.Value = DBNull.Value;
                        }
                        else
                        {
                            prmname.Value = obj.name;
                        }
                        strWhere += " [name] LIKE @name OR ";
                        lstParameters.Add(prmname);
                     }



                    

                    if (obj.principal_id != -1)
                    {
                        DbParameter prmprincipal_id = con.createParameter();
                        prmprincipal_id.ParameterName = "@principal_id";
                        prmprincipal_id.DbType =DbType.Int32;
                        if (obj.principal_id == null)
                        {
                            prmprincipal_id.Value = DBNull.Value;
                        }
                        else
                        {
                            prmprincipal_id.Value = obj.principal_id;
                        }
                        strWhere += " [principal_id]=@principal_id OR ";
                        lstParameters.Add(prmprincipal_id);
                     }



                    

                    if (obj.diagram_id != -1)
                    {
                        DbParameter prmdiagram_id = con.createParameter();
                        prmdiagram_id.ParameterName = "@diagram_id";
                        prmdiagram_id.DbType =DbType.Int32;
                        if (obj.diagram_id == null)
                        {
                            prmdiagram_id.Value = DBNull.Value;
                        }
                        else
                        {
                            prmdiagram_id.Value = obj.diagram_id;
                        }
                        strWhere += " [diagram_id]=@diagram_id OR ";
                        lstParameters.Add(prmdiagram_id);
                     }



                    

                    if (obj.version != null)
                    {
                        DbParameter prmversion = con.createParameter();
                        prmversion.ParameterName = "@version";
                        prmversion.DbType =DbType.Int32;
                        if (obj.version == null)
                        {
                            prmversion.Value = DBNull.Value;
                        }
                        else
                        {
                            prmversion.Value = obj.version;
                        }
                        strWhere += " [version]=@version OR ";
                        lstParameters.Add(prmversion);
                     }



                    

                    if (obj.definition != null)
                    {
                        DbParameter prmdefinition = con.createParameter();
                        prmdefinition.ParameterName = "@definition";
                        prmdefinition.DbType =DbType.Binary;
                        if (obj.definition == null)
                        {
                            prmdefinition.Value = DBNull.Value;
                        }
                        else
                        {
                            prmdefinition.Value = obj.definition;
                        }
                        strWhere += " [definition]=@definition OR ";
                        lstParameters.Add(prmdefinition);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<sysdiagrams> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<sysdiagrams> SearchOrLike(sysdiagrams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<sysdiagrams> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            